﻿@model IEnumerable<TaskManage.Models.Task>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.TaskPriority)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Content)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AddTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.TaskState)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FinishedTime)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.uid)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @{
                string str = "";
                if (item.TaskPriority == 1)
                {
                    str = "高";
                }
                else if (item.TaskPriority == 2)
                {
                    str = "中";
                }
                else
                {
                    str = "低";
                }

            }
            @Html.DisplayFor(modelItem => str)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Content)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.AddTime)
        </td>
        <td>
            @{
                string state = "";
                if (item.TaskState == 1)
                {
                    state = "已完成";
                }
                else
                {
                    state = "未完成";
                }
            }
            @Html.DisplayFor(modelItem => state)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.FinishedTime)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.uid)
        </td>
        <td>
            @Html.ActionLink("修改", "Edit", new { id=item.TaskID }) |
            @Html.ActionLink("详情", "Details", new { id=item.TaskID }) |
            @*@Html.ActionLink("删除", "Index", new { id=item.TaskID })*@
            <a href="#" data-del="@item.TaskID">删除</a>
        </td>
    </tr>
}
</table>
@section scripts{
    <script type="text/javascript">
        $(function Delete() {
            $("a[data-del]").click(function () {
                var $this = $(this)
                var id = $this.attr("data-del");    // 获取选中行id
                if (!confirm("确定要删除" + id + "吗？"))
                    return
                $.post("@Url.Content("~/Home/Delete")", { id: id }, function (res) {    
                    if (res) {
                        //location.reload();
                        $this.closest("tr").remove();//删除选中行
                    }
                })
            })
        })
    </script>
    
            }
